package com.wyp168.leetcode;

import javax.validation.constraints.Min;

/**
 * @ClassName MinAddToMakeValid
 * @Description leetcode： 921.使括号有效的最小添加
 * @Author wyp168
 * @Date 2022/10/4 20:27
 */
public class MinAddToMakeValid {
    public static void main(String[] args) {
        MinAddToMakeValid minAddToMakeValid = new MinAddToMakeValid();
        String s = "(((";

        System.out.println(minAddToMakeValid.minAddToMakeValid(s));
    }

    public int minAddToMakeValid(String s) {
        int l = 0, r = 0;

        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) == '(') {
                l ++;
            } else if (s.charAt(i) == ')') {
                if (l > 0)
                    l --;
                else
                    r ++;
            }
        }
        return l + r;
    }
}
